<?php

namespace Our\Upload;

/**
 * 上传参数配置
 */
class Config {

    /**
     * 文件保存目录
     * 
     * @var string
     */
    protected $_dir;

    /**
     * 保存子目录计算方式
     * 
     * @param string
     */
    protected $_subDirType;

    /**
     * 上传表单file控件name值
     * 
     * @var string
     */
    protected $_filename;

    /**
     * 另存文件名
     * 
     * @var string
     */
    protected $_saveFilename;

    /**
     * 大小限制
     * 
     * @var int 
     */
    protected $_size;

    /**
     * 后缀名限制
     * 
     * @var array
     */
    protected $_ext;

    public function __construct($config = array()) {
        $this->init();

        foreach ($config as $key => $value) {
            if (!$value) {
                continue;
            }
            $methodName = 'set' . ucfirst($key);
            if (method_exists($this, $methodName)) {
                $this->$methodName($value);
            }
        }
    }

    public function init() {
        $this->setSize(5000 * 1024);
        $this->setDir('/upload');
        $this->setSubDirType('date');
        $this->setFilename('file');
        $this->setSaveFilename(null);
        $this->setExt(array('png', 'gif', 'jpg', 'jpeg'));
    }

    public function setDir($dir) {
        $this->_dir = $dir;
    }

    public function getDir() {
        return $this->_dir;
    }

    public function setSubDirType($subDirType) {
        $this->_subDirType = $subDirType;
    }

    public function getSubDirType() {
        return $this->_subDirType;
    }

    public function setFilename($filename) {
        $this->_filename = $filename;
    }

    public function getFilename() {
        return $this->_filename;
    }

    public function setSaveFilename($saveFilename) {
        $this->_saveFilename = $saveFilename;
    }

    public function getSaveFilename() {
        return $this->_saveFilename;
    }

    public function setSize($size) {
        $this->_size = $size;
    }

    public function getSize() {
        return $this->_size;
    }

    public function setExt($ext) {
        $this->_ext = $ext;
    }

    public function getExt() {
        return $this->_ext;
    }

}